package com.svse.designPattern.behaviour.mediator.impl;

import com.svse.designPattern.behaviour.mediator.service.Colleague;
import com.svse.designPattern.behaviour.mediator.service.Mediator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2020/8/8 22:50
 */
public class ConcreteMediator extends Mediator {
    private List<Colleague> colleagues=new ArrayList<Colleague>(10);
    @Override
    public void register(Colleague colleague) {
        if(!colleagues.contains(colleague)){
            colleagues.add(colleague);
            colleague.setMediator(this);
        }
    }

    @Override
    public void relay(Colleague colleague) {
        colleagues.forEach(temp_col -> {
            if(temp_col.equals(colleague)){
                ((Colleague)temp_col).receive();
            }
        });
    }
}
